package space.sakana.edusysback.controller;

import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import space.sakana.edusysback.result.Result;
import space.sakana.edusysback.service.SubjectService;

@RestController
@RequestMapping("/api/subject")
public class SubjectController {

    private SubjectService subjectService;

    @Autowired
    public void autowiredService(SubjectService subjectService){
        this.subjectService = subjectService;
    }

    @RequestMapping("/all")
    public Result getAllSubject(HttpServletRequest request, HttpServletResponse response){
        return subjectService.getAllSubject(request, response);
    }

    @RequestMapping("/add")
    public Result addSubject(@RequestParam String data, HttpServletRequest request, HttpServletResponse response){
        return subjectService.addSubject(data, request, response);
    }

    @RequestMapping("/update")
    public Result updateSubject(@RequestParam String data, HttpServletRequest request, HttpServletResponse response){
        return subjectService.updateSubject(data, request, response);
    }

    @RequestMapping("/{sid}")
    public Result getSubject(@PathVariable int sid, HttpServletRequest request, HttpServletResponse response){
        return subjectService.getSubject(sid, request, response);
    }

    @RequestMapping("/delete/{sid}")
    public Result deleteSubject(@PathVariable int sid, HttpServletRequest request, HttpServletResponse response){
        return subjectService.deleteSubject(sid, request, response);
    }

}
